home *** CD-ROM | disk | FTP | other *** search
- /* Define everything that all of the various pieces of code will be using */
-
- #include <stdio.h>
- #include <signal.h>
- #include <strings.h>
- #include <syslog.h>
- #include <nlist.h>
- #include <errno.h>
- #include <ctype.h>
- #include <sys/param.h>
- #include <sys/errno.h>
- #include <sys/file.h>
- #include <sys/ioctl.h>
- #include <sys/wait.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <varargs.h>
-
- #include "newsxd.h"
- #include "patchlevel.h"
-
- /* If it's good enough for news 2.11, it's good enough for me ... */
-
- #ifdef BSD4_2
- #include <sys/time.h>
- #else
- #include <time.h>
- #endif
-
- #include <sys/resource.h>
-
- #if defined(mips) & defined(ultrix)
- #include <sys/../h/fixpoint.h>
- #endif
-
- char *calloc();
-
- #define foreach(ctl, list) for (ctl = list; ctl != NULL; ctl = ctl->next)
-
- #ifdef CNEWSLOCKING
- extern char *progname;
- #endif
-
- int debug, /* is debugging enabled */
- DEBUG, /* painfully verbose debugging is enabled */
- newsxdebug, /* run xmitter synchronously with debugging? */
- tallying, /* is use of a tally file enabled? */
- locking, /* is use of a locking file enabled? */
- CONFIGCHANGED, /* a new configuration was read in */
- #ifdef FAKESYSLOG
- CONFIGCHANGEDFILE, /* a new configuration was read in */
- #endif
- queueinterval, /* number of seconds between xmit checks */
- daemon_idle, /* prevent newsxd from running queue if set */
- pidlist[MAXXMITTERS]; /* map pid --> xmitter quicker */
-
- struct host *pidmap[MAXXMITTERS];
-
- char batchfile[MAXPATHLEN], /* file inews places article IDs/paths in */
- workfile[MAXPATHLEN], /* file to use for transmitter work file */
- xmitlogs[MAXPATHLEN], /* where to log the output of transmitters */
- tallyfile[MAXPATHLEN], /* where the tally file can be found */
- statusfile[MAXPATHLEN], /* where newsxd's status should be written */
- pidfile[MAXPATHLEN], /* where newsxd's pid should be written */
- #ifdef FAKESYSLOG
- fakelogfile[MAXPATHLEN],/* where is the newsxd log file? */
- #endif
- configfile[MAXPATHLEN]; /* where is the newsxd configuration file? */
-
- /* STRUCT OPTIONS
- * Used to define the options controlling the starting of transmitters for
- * classes and hosts.
- *
- * interval : minimum start-to-start interval for each host's transmitter
- * startint : minimum interval between starting transmitters in this class
- * ttl : maximum time-to-live (secs) for a transmitter in this class
- * ttlpenalty : penalty time (secs) for a transmitter exceeding the ttl
- * deltanice : amount to change nice before execing the transmitter
- * maxload : maximum load where new xmitters can be started for this class
- *
- */
-
- typedef struct options {
-
- int deltanice;
- int interval;
- int startint;
- int ttl;
- int ttlpenalty;
- int maxload;
-
- };
-
- /*
- * STRUCT CLASS
- * Contains the current state and description of each class of transmitters
- * that newsxd handles.
- *
- * classname : textual name of this transmission class
- * maxxmits : maximum number of simultaneous transmitters for this class
- * curxmits : current number of active transmitters for this class
- * laststart : last time a transmitter was started for this class
- * xmitsernum : transmission serial number used for fair news transmission
- * options : defines default transmitter startup parameters for this class
- * members : number of hosts that are a member of this class
- * flags : special option flags for this class
- * 0 : don't rename <batchfile> to <workfile>
- * 1 : don't look for <batchfile> or <workfile>
- * xpath : file path for an alternate transmission program
- * xargv : arguments to be passed to the alternate transmitter
- * xargc : number of arguments to be passed to the alternate xmitter
- * valid : used to detect which classes are valid after a config update
- * next : pointer to the next class descriptor in the list
- *
- */
-
- struct class {
-
- char classname[MAXCLASSNAMELEN];
- int maxxmits;
- int curxmits;
- int laststart;
- int xmitsernum;
- int members;
- struct options options;
- char slots[MAXCLASSXMITTERS];
- int flags[MAXCLASSFLAGS];
- char batchfile[MAXPATHLEN];
- char workfile[MAXPATHLEN];
- char xpath[MAXPATHLEN];
- char *xargv[MAXEXECARGS];
- int xargc;
- char *debugargv[MAXEXECARGS];
- int debugargc;
- int valid;
- struct class *next;
-
- };
-
- /*
- * STRUCT HOST
- * Contains the current state and description of each host that newsxd
- * will be communicating with.
- *
- * hostname : name of the host to pass to the transmitter
- * class : name of the transmission class this host is in
- * times : list of valid times to transmit in UUCP L.sys format
- * pid : pid of forked transmitter
- * lasttime : last time transmitter was forked off
- * xmitsernum : transmission serial number used for fair news transmission
- * penaltytime : host xmitted to past ttl; secs before penalty is over
- * whynot : why is there no transmitter running for this host NOW?
- * valid : used to detect which hosts are valid after a config update
- * options : defines default transmitter startup parameters for this host
- * next : pointer to next host in the list of all hosts
- * xargv : arguments to be passed to the transmitter
- * xargc : number of arguments to be passed to the transmitter
- *
- */
-
- struct host {
-
- char hostname[MAXHOSTNAMELEN];
- char class[MAXCLASSNAMELEN];
- char times[MAXTIMENAMELEN];
- int pid;
- int lasttime;
- int penaltytime;
- int xmitsernum;
- int whynot;
- int valid;
- int classslot;
- struct options options;
- char *xargv[MAXEXECARGS];
- int xargc;
- struct host *next;
-
- };
-
- struct class *classlist;
- struct host *hostlist;
-
- /* Predefine the return types of all of the functions */
-
- void addclass();
- void addhost();
- void clear_invalid();
- void daemon_start();
- void debug_off();
- void debug_on();
- void dprintf();
- void Dprintf();
- void dump_config();
- void dump_info();
- void idle();
- void reset();
- struct class *getclass();
- void freeclassslot();
- int getclassslot();
- int getla();
- void kill_children();
- void log();
- void logerr();
- void make_invalid();
- int parsetime();
- void processarg();
- void read_config();
- void run_queue();
- int validtime();
- void xmit_done();
-